snippet table "[key] -> valuewa"
${1:name} = {${2}}
endsnippet

snippet if	"if ... then"
if ${1:condition} then
	${2:--statements}
else
	//
end
endsnippet

snippet el	"elseif ... then"
elseif ${1:condition} then
	${2:--statements}
endsnippet

snippet while	"while ... do"
while ${1:condition} do
	${2:--statements}
end
endsnippet

snippet repeat	"repeat ... until"
repeat
	${1:--statements}
until ${2:condition}
endsnippet

snippet for	"numeric for loop"
for ${1:variable} = ${2:start}, ${3:end}, ${4:step} do
	${5:--print("key = " .. key ..", val = " ..val)}
end
endsnippet

snippet ipairs "iterate over the pairs, up to the first integer key absent from the table." b
for ${1:key}, ${2:val} in ipairs(${3:table}) do
	${4:--print("key = " , key , val = " ,val)}
end
endsnippet

snippet pairs "iterate over all key–value pairs of table t" b
for ${1:key}, ${2:val} in pairs(${3:table}) do
	${4:--print("key = " , key , val = " , val)}
end
endsnippet

snippet do	"do ... end"
do
	${1:--block}
end
endsnippet

snippet fun	"normal function"
function ${1:name}(${2:args})
	${3:--statements}
	return
end
endsnippet

snippet funa	"anonymous function"
${1:name} = function ()
	${2:--statements}
	return
end
endsnippet

snippet funv "variable function" !b
function ${1:name}(...)
	--local variable
    for idx,val in ipairs{...} do
	--
	end
	--return variable
endsnippet


snippet class "use table as class" b
${1:name} = {
	--variable = 0
}
function $1:new(o)
	o = o  or {}
	setmetatable(o, self)
	self._index = self
end


function $1.${2:function}(self, para)
end

function $1.${2:function}:(para)
end
endsnippet

snippet create "creates new coroutines(in the suspended state)"
${1:co} = coroutine.create(
	function()
		${2:--code}
	end)

endsnippet

snippet yield "Suspends the execution of the calling coroutine."
coroutine.yield(${1:ret1})
endsnippet

snippet resume "Starts or continues the execution of coroutine"
coroutine.resume(${1:coroutine})
endsnippet


snippet module "generate the template of module" 
local M = {}

M.num = 1

-- 匿名函数
M.getInfo  = function ()
    return M.num
end

-- 构造函数
function M:new(o)
    local t = o or{}
    return t
end

-- 普通成员函数
function M.setInfo(num)
    M.num = num
end

return M
endsnippet


snippet string_find "If finds a match, returns the indices; otherwise, return nil" 
string.find(${1:s}, ${2:pattern})
endsnippet

snippet string_len "return the length of a string" b

endsnippet
